import {Mongo} from 'meteor/mongo'
import {Meteor} from 'meteor/meteor'
import {SimpleSchema} from 'meteor/aldeed:simple-schema'

export default class Collection extends Mongo.Collection {
  constructor ({name, publish, schema}) {
    super(name)

    // 设置集合名称
    this.collectionName = name
    // 设置集合发布
    this.collectionPublish = () => {
      publish.forEach(({name, callback}) => {
        Meteor.publish(name, callback)
      })
    }

    if (schema) {
      this.attachSchema(new SimpleSchema(schema))
    }
  }
}
